﻿using System;

class GreatestCommonDivisor
{
    static void Main()
    {
        int firstNumber;
        int secondNumber;
        int greatestCommonDivisor;


        Console.WriteLine("Type first number:");
        bool isFirstNumberValid = int.TryParse(Console.ReadLine(), out firstNumber);
        Console.WriteLine("Type second number:");
        bool isSecondNumberValid = int.TryParse(Console.ReadLine(), out secondNumber);

        if (isFirstNumberValid && isSecondNumberValid)
        {
            int dividend;
            int divisor;

            if (firstNumber<secondNumber)
            {
                dividend = secondNumber;
                divisor = firstNumber;
            }
            else
            {
                dividend = firstNumber;
                divisor = secondNumber;
            }
            while (true)
            {
                if (dividend%divisor==0)
                {
                    greatestCommonDivisor = divisor;
                    break;
                }
                int remainder = dividend % divisor;
                dividend = divisor;
                divisor = remainder;                
            }

            Console.WriteLine("And the greatest common divisor is:{0}",greatestCommonDivisor);
            
        }
        else
        {
            Console.WriteLine("Your input isn`t OK!!!");
        }
    }
}